<?php

namespace App\Models\System;

use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Casts\Attribute;

class DictItem extends BaseModel
{
    protected $fillable = [
        'title',
        'dict_id',
        'value',
        'sort',
        'status',
    ];

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'created_at' => 'datetime:Y-m-d H:i:s',
            'updated_at' => 'datetime:Y-m-d H:i:s',
        ];
    }

    protected function title(): Attribute
    {
        return Attribute::make(
            get: function ($value) {
                return __($value);
            },
        );
    }

    /**
     * 字典项
     */
    public function items()
    {
        return $this->hasMany(Role::class);
    }
}
